package bishi.kedaxunfei;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * @Classname Main1
 * @Description TODO
 * @Date 2021/10/10 19:54
 * @Created by ASUS
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        scanner.nextLine();
        List<Integer> a = Arrays.stream(scanner.nextLine()
                .split(" ")).map(Integer::parseInt).collect(Collectors.toList());
        if (a.size() == 1) {
            System.out.println(1);
            return;
        }
        int[] array = new int[a.size()];
        for (int i = 0; i < array.length; i++) {
            array[i] = a.get(i);
        }
        int cnt = 0;
        cnt = Math.max(cnt, f(array));
        int tmp;
        for (int i = 0; i < array.length - 1; i++) {
            tmp = array[i];
            array[i] = array[i + 1];
            array[i + 1] = tmp;
            cnt = Math.max(cnt, f(array));
            tmp = array[i];
            array[i] = array[i + 1];
            array[i + 1] = tmp;
        }
        System.out.println(cnt);
    }

    public static int f(int[] array) {
        int cnt = 0;
        for (int x = 0, y = 0; x < array.length && y < array.length; y++) {
            if (array[x] != array[y]) {
                cnt = Math.max(cnt, y - x);
                x = y;
            }
        }
        return cnt;
    }
}
